package com.frxuexi.demo01_compose.view

import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Person
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.apps.Greeting

sealed class NavItem(val route: String, val title: String, val icon: ImageVector) {
    object HomePage : NavItem("home", "首页", Icons.Default.Home)
    object MyPage : NavItem("my", "我的", Icons.Default.Person)
}

@Composable
fun MainPage(name: String, pass: Int) {
//    Text(text = name+pass)
    val list = listOf<NavItem>(NavItem.HomePage, NavItem.MyPage)
    val navController = rememberNavController()
    Scaffold(bottomBar = {
//        val navBackStackEntry by navController.currentBackStackEntryAsState()
//        val currentDestination = navBackStackEntry?.destination
        NavigationBar {
            list.forEach { screen ->
                NavigationBarItem(
                    icon = { Icon(imageVector = screen.icon, contentDescription = "")},
                    label = { Text(text = screen.title)},
                    selected = false,
                    onClick = {
                        navController.navigate(screen.route)
                    })
            }
        }
    }) { p ->
        NavHost(
            navController = navController,
            startDestination = "home",
            Modifier.padding(p)
        ) {
//            composable("home") { HomePage() }
            composable("home") { Greeting(name = "首页") }
            composable("my") { MyStaggeredGrid()/*{ ToastUtils.showLong("点击了") } */}

        }

    }
}